﻿
#region Usings

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Threading.Tasks;
using System.Collections;
using System.Threading;
using System.Windows.Threading;
using System.Windows.Controls.Primitives;
using System.IO;
using System.Windows.Markup;
using System.Reactive;
using System.Reactive.Linq;
using FasterWPF;
using System.Reflection;
using System.Collections.ObjectModel;
using System.Dynamic;
using System.Runtime.InteropServices;
using System.Reactive.Concurrency;
using System.Globalization;
using System.Data;
using wpfToolkit = Xceed.Wpf.Toolkit;
using System.Windows.Forms.Integration;
//using System.Windows.Forms.DataVisualization;
using System.Windows.Media.Animation;
using FasterWPF.Selectors;
using FasterWPF.Observables;
#endregion

namespace FasterWPFDemo
{
    public partial class CPSWindow : CPSBaseWindow
    {
        #region Class-Level Variables

        #region GUIDs

        // a lot of Guids here but typically this could be more data driven by records (guids) stored in a database?
        // also, feel free to use the version of BeginComposite with zero parms that auto-generates a guid

        string cnvsguid0 = Guid.NewGuid().ToString();
        string cnvsguid1 = Guid.NewGuid().ToString();
        string cnvsguid2 = Guid.NewGuid().ToString();
        string cnvsguid3 = Guid.NewGuid().ToString();
        string dockguid3 = Guid.NewGuid().ToString();
        string dockguid4 = Guid.NewGuid().ToString();
        string dockguid5 = Guid.NewGuid().ToString();
        string userCtlGuid1 = Guid.NewGuid().ToString();
        string userCtlGuid2 = Guid.NewGuid().ToString();
        string userCtlGuid3 = Guid.NewGuid().ToString();
        string userCtlGuid4 = Guid.NewGuid().ToString();
        string userCtlGuid5 = Guid.NewGuid().ToString();
        string userCtlGuid6 = Guid.NewGuid().ToString();
        string userCtlGuid7 = Guid.NewGuid().ToString();
        string userCtlGuid8 = Guid.NewGuid().ToString();
        string userCtlGuid9 = Guid.NewGuid().ToString();
        string userCtlGuid10 = Guid.NewGuid().ToString();
        string tabguid0 = Guid.NewGuid().ToString();
        string tabguid1 = Guid.NewGuid().ToString();
        string tabguid2 = Guid.NewGuid().ToString();
        string tabguid3 = Guid.NewGuid().ToString();
        string tabguid4 = Guid.NewGuid().ToString();
        string tabguid5 = Guid.NewGuid().ToString();
        string tabguid6 = Guid.NewGuid().ToString();
        string tabguid7 = Guid.NewGuid().ToString();
        string tabguid8 = Guid.NewGuid().ToString();
        string tabguid9 = Guid.NewGuid().ToString();
        string mgguid0 = Guid.NewGuid().ToString();
        string mgguid1 = Guid.NewGuid().ToString();
        string mgguid2 = Guid.NewGuid().ToString();
        string mgguid3 = Guid.NewGuid().ToString();
        string mnuguid0 = Guid.NewGuid().ToString();
        string mnuguid1 = Guid.NewGuid().ToString();
        string mnuguid2 = Guid.NewGuid().ToString();
        string mnuguid3 = Guid.NewGuid().ToString();
        string mnuguid4 = Guid.NewGuid().ToString();
        string mnuguid5 = Guid.NewGuid().ToString();
        string submnuguid2 = Guid.NewGuid().ToString();
        string bdrguid1 = Guid.NewGuid().ToString();
        string bdrguid2 = Guid.NewGuid().ToString();
        string bdrguid3 = Guid.NewGuid().ToString();
        string chkguid2 = Guid.NewGuid().ToString();
        string chkguid3 = Guid.NewGuid().ToString();
        string rdoguid0 = Guid.NewGuid().ToString();
        string rdoguid1 = Guid.NewGuid().ToString();
        string rdoguid2 = Guid.NewGuid().ToString();
        string rdoguid3 = Guid.NewGuid().ToString();
        string tabheaderguid1 = Guid.NewGuid().ToString();
        string drpGuid2 = Guid.NewGuid().ToString();
        string drpGuid3 = Guid.NewGuid().ToString();
        string gridguid3 = Guid.NewGuid().ToString();
        string gridguid4 = Guid.NewGuid().ToString();
        string gridguid5 = Guid.NewGuid().ToString();
        string gridguid6 = Guid.NewGuid().ToString();
        string gridguid7 = Guid.NewGuid().ToString();
        string myBorderGuid3 = Guid.NewGuid().ToString();
        string gxguid2 = Guid.NewGuid().ToString();
        string gxguid3 = Guid.NewGuid().ToString();
        string gxguid4 = Guid.NewGuid().ToString();
        string gxguid5 = Guid.NewGuid().ToString();
        string gxguid6 = Guid.NewGuid().ToString();
        string gxguid7 = Guid.NewGuid().ToString();
        string trvguid1 = Guid.NewGuid().ToString();
        string trvguid2 = Guid.NewGuid().ToString();
        string trvguid3 = Guid.NewGuid().ToString();
        string trvguid4 = Guid.NewGuid().ToString();

        #endregion

        Menu mnu = null;
        Grid mainGrid = null;
        TabControl tabCtl = null;
        Border customDialog = null;

        #endregion

        public CPSWindow()
        {
            //InitializeComponent(); NOT NEEDED SINCE NO XAML. Call base.StartInitializeComponent(); at the beginning of the Constructor and base.EndInitializeComponent() at the end instead
            base.StartInitializeComponent(Brushes.Silver, new Thickness(2));

            //base.Canvas is available

            Title = "WPF Composites";
            GlobalStoreService.CreateGlobalStores();
         
            customDialog = new Border();
            tabCtl = new TabControl();
            this.Background = Brushes.Gray;

            mnu = MenuBarService.CreateMenuBar();

            #region Store Class-Level Variables for Re-Sizing

            //Store handles to the main layout controls to allow fine-grained re-sizing based on
            //window size and re-sized event. This is NOT required, just my preference.
            //Feel free to use regular WPF star sizing, dockpanel fill, etc.

            //  Application.Current.Properties["CoreControlFull1"] = myGrid;
            Application.Current.Properties["CoreControlFull2"] = base.Canvas;
            Application.Current.Properties["TabControl"] = tabCtl;
            Application.Current.Properties["MenuControl"] = mnu;
            Application.Current.Properties["Window"] = this;
            
            Application.Current.Properties["AdornerDecorator"] = base.AdornerDecorator;
            Application.Current.Properties["Canvas"] = base.Canvas;
            Application.Current.Properties["CanvasGuid0"] = cnvsguid0.ToString();
            Application.Current.Properties["DialogGuid"] =Guid.NewGuid().ToString();
            // Application.Current.Properties["SubControl1"] = trv;
            //  Application.Current.Properties["SubControl2"] = scvw;
            // Application.Current.Properties["SubControl3"] = myDockPanel;
            // Application.Current.Properties["SubControl4"] = scrollViewer4WrapPanel;
            //  Application.Current.Properties["SubControl5"] = myDockPanel2;

            #endregion

            MenuBarService.CreateMenuBarItems(mnu, base.Canvas, cnvsguid1, cnvsguid2, cnvsguid3);
            //Aero menu option - chrome not fully removed yet . . .
            //MenuBarService.CreateAeroMenuBarItems(mnu, cnvs, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString());

            customDialog = CustomDialogExample.InitializeDialogExample(base.Canvas, cnvsguid0);
            Application.Current.Properties["Dialog"] = customDialog;

            #region Main Grid

            //Main Grid
            mainGrid = new Grid();
            mainGrid.Name = "mainGrid";
            mainGrid.Initialize(double.NaN, double.NaN, 10D, ContainerType.HorizontalPanel, 23, 1, 1.0, GridUnitType.Star, 1.0, GridUnitType.Star, 23D, GridUnitType.Pixel);
            mainGrid.ShowGridLines = false;
            mainGrid.BeginSettings<Grid>().SetItemBorderSettings<Grid>(double.NaN, double.NaN, Brushes.Silver, new Thickness(2)).EndSettings<Grid>();
            mainGrid.Visibility = Visibility.Hidden;

            //Add Menu to Grid
            mainGrid.BeginComposite<Grid>(mgguid0)
                .AddExisting<Menu, Grid>(0, 0, mnu)
                .EndComposite<Grid, GridArgs>(new GridArgs(0, 0));

            mainGrid.BeginComposite<Grid>(mgguid1)
                .AddExisting<TabControl, Grid>(1, 0, tabCtl)
                .EndComposite<Grid, GridArgs>(new GridArgs(1, 0));

            Grid.SetRowSpan(mainGrid.GetCompositeFromParent<Grid>(mgguid1), 24);
            Grid.SetColumnSpan(mainGrid.GetCompositeFromParent<Grid>(mgguid1), 1);
            Grid.SetRowSpan(mainGrid.GetCompositeFromParent<Grid>(mgguid0), 1);
            Grid.SetColumnSpan(mainGrid.GetCompositeFromParent<Grid>(mgguid0), 1);
            
            #endregion
            
            base.AddMainParentToWindow(adornerDecorator =>
            {
                adornerDecorator.BeginComposite<AdornerDecorator>()
                    .AddExisting<Grid, AdornerDecorator>(0, 0, mainGrid)
                    .EndComposite<AdornerDecorator, AdornerDecoratorArgs>(null);
            });

            base.AdornerDecorator.SetSelectorClass("testThisSelector");

            #region Test Selectors code

            //List<FrameworkElement> allParentsInPath = new List<FrameworkElement>();
            //FrameworkElement topElement = Selectors.RecurseUpParentFrameworkElements(false, 100, allParentsInPath, mainGrid);
            //FrameworkElement elementOfType = Selectors.RecurseUpParentFrameworkElementsUntilType(false, 100, allParentsInPath, mainGrid, "Border");

            //FrameworkElement elementWithName = Selectors.RecurseUpParentFrameworkElementsUntilName(false, 100, allParentsInPath, mainGrid, "mainGrid");

            //FrameworkElement elementWithClass = Selectors.RecurseUpParentFrameworkElementsUntilClass(false, 100, allParentsInPath, mainGrid, "testThisSelector");

            //TEST SELECTORS - these will recurse using EITHER the VisualTree OR LogicalTree, as needed
            FrameworkElement topElement = FasterWPF.Selectors.Select.RecurseUpParentFrameworkElements(false, 100, mainGrid);
            FrameworkElement elementOfType = FasterWPF.Selectors.Select.RecurseUpParentFrameworkElementsUntilType(false, 100, mainGrid, "Border");

            FrameworkElement elementWithName = FasterWPF.Selectors.Select.RecurseUpParentFrameworkElementsUntilName(false, 100, mainGrid, "mainGrid");

            FrameworkElement elementWithClass = FasterWPF.Selectors.Select.RecurseUpParentFrameworkElementsUntilClass(false, 100, mainGrid, "testThisSelector");

            #endregion

            #region Tab Control and Tab Items

            TabControlService.InitTabControl(tabCtl);

            TabItem tabItm1 = TabControlService.CreateTabItem1("Grid / ListBox", Brushes.White, Brushes.Snow, Brushes.Black, Brushes.SlateGray, Brushes.Blue, tabguid0, tabCtl, userCtlGuid1);

            TabItem tabItm2 = TabControlService.CreateTabItem2("Wrap Panel", Brushes.WhiteSmoke, Brushes.Snow, Brushes.Black, Brushes.SlateGray, Brushes.Gold, tabguid1, tabCtl, userCtlGuid2);

            TabItem tabItm3 = TabControlService.CreateTabItem3("Rich Text", Brushes.WhiteSmoke, Brushes.Snow, Brushes.Black, Brushes.SlateGray, Brushes.Red, tabguid2, tabCtl, userCtlGuid3);

            TabItem tabItm4 = TabControlService.CreateTabItem4("Tree View", Brushes.LightBlue, Brushes.Snow, Brushes.Black, Brushes.SlateGray, Brushes.Turquoise, tabguid3, tabCtl, userCtlGuid4);

            TabItem tabItm5 = TabControlService.CreateTabItem5("Chart", Brushes.LightGreen, Brushes.Snow, Brushes.Black, Brushes.SlateGray, Brushes.Green, tabguid4, tabCtl, userCtlGuid5);

            TabItem tabItm6 = TabControlService.CreateTabItem6("Dock Panel", Brushes.Lavender, Brushes.Snow, Brushes.Black, Brushes.SlateGray, Brushes.MediumPurple, tabguid5, tabCtl, userCtlGuid6);

            TabItem tabItm7 = TabControlService.CreateTabItem7("ToolBars / Xceed DataGrid", Brushes.LightSalmon, Brushes.Snow, Brushes.Black, Brushes.SlateGray, Brushes.Orange, tabguid6, tabCtl, userCtlGuid7);

            TabItem tabItm8 = TabControlService.CreateTabItem8("Plain WPF DataGrid", Brushes.AliceBlue, Brushes.Snow, Brushes.Black, Brushes.SlateGray, Brushes.Navy, tabguid7, tabCtl, userCtlGuid8);

            TabItem tabItm9 = TabControlService.CreateTabItem9("Group Box", BrushExt.CreateSolidColorBrushFromRGB(173, 255, 47, 70), Brushes.Snow, Brushes.Black, Brushes.SlateGray, Brushes.LawnGreen, tabguid8, tabCtl, userCtlGuid9);

            TabItem tabItm10 = TabControlService.CreateTabItem10("Content Control 3D", Brushes.White, Brushes.Snow, Brushes.Black, Brushes.SlateGray, Brushes.LightBlue, tabguid9, tabCtl, userCtlGuid10, "Black", "LightGray", "Gold", "Gold", "White", "Silver", "Gray");

            Application.Current.Properties["CreateTabItem1"] = new Action(
             () =>
             {
                 TabControlService.CreateTabItem1("Grid / ListBox", Brushes.White, Brushes.Snow, Brushes.Black, Brushes.SlateGray, Brushes.Blue, tabguid0, tabCtl, userCtlGuid1);
             });

            Application.Current.Properties["CreateTabItem2"] = new Action(
             () =>
             {
                 TabControlService.CreateTabItem2("Wrap Panel", Brushes.WhiteSmoke, Brushes.Snow, Brushes.Black, Brushes.SlateGray, Brushes.Gold, tabguid1, tabCtl, userCtlGuid2);
             });

            Application.Current.Properties["CreateTabItem3"] = new Action(
              () =>
              {
                  TabControlService.CreateTabItem3("Rich Text", Brushes.WhiteSmoke, Brushes.Snow, Brushes.Black, Brushes.SlateGray, Brushes.Red, tabguid2, tabCtl, userCtlGuid3);
              });

            Border userControlChildComposite1 = this.SelectCompositeByKey(userCtlGuid1);
            userControlChildComposite1.Visibility = Visibility.Hidden;
            #endregion
            
            #region Test Selectors Engine

            TestSelectorsEngineService.Run(this);

            #endregion

            #region *************  SNIPPETS TESTING OUT CODE  *************

            //Border userControlChildComposite = this.SelectCompositeByKey(userCtlGuid);
            //var handleToUserControl = userControlChildComposite.GetParentFromComposite<UserControl>();

            //Dispose Events down thru all children, including down thru FlatButton which is itself a Parent . . .
            //this.DisposeEventsOnAllParents();

            //myListBox.UnsubscribeBorderEvents<ListBox>();

            //List<Grid> gridChildren = this.SelectGridsFromAllGridComposites(false);
            //gridChildren.ForEach(grd => { grd.ShowGridLines = false; });  

            //rowGrid.AddImage(str.Item2, 0, 0, varyImage, 28).AddText(str.Item2, 0, 1, varyText+str.Item3+": ").AddTextWithToolTipEnabled(str.Item2, 0, 2, str.Item2).SetMouseOverColor(0, 0, Brushes.BlanchedAlmond);

            //myListBox.AddAlternatingRows(Brushes.LawnGreen, Brushes.Transparent);

            //string z=Guid.NewGuid().ToString();
            //myListBox.AddRowElements(z, rowGrid =>
            //{
            //    rowGrid.AddText(z, 0, 1, " test 100 ").AddTextWithToolTipEnabled(z, 0, 2, z).SetMouseOverColor(0, 0, Brushes.BlanchedAlmond);
            //});

            //myListBox.Dispose();
            //myListBox.RemoveByKey(z);
            //myListBox.GetTextBlock(oneGUID, 0, 2).Visibility = Visibility.Hidden;  

            //   Track tr = box.GetVerticalScrollTrack();
            //   Thumb tumb = box.GetVerticalScrollThumb();             
            //   tumb.Background = Brushes.Gray;
            //   tumb.BorderBrush = Brushes.GhostWhite;
            //   tumb.BorderThickness = new Thickness(0, 0, 0, 0);
            //   myListBox.UnsubscribeMouseDoubleClickAll();
            //   myListBox.UnsubscribeMouseDoubleClickByKey(twoGUID);
            #endregion

            #region ************* REMAINING TO-DO ITEMS *************

            //Datepicker , Calender
            //  eight controls called the WPF Bag O’ Tricks download?  It includes the following controls: AnimatingTilePanel, ColorPicker, InfoTextBox, ListPager, NumericUpDown, Reveal, TransitionsPresenter, TreeMapPanel. Add support for these too?

            //setmouseovercolor by row col?

            //subscribe to any event side effects parameter

            //create new method RemoveAtRowCol<K,T> at specific row and column

            //NOTE: REMOVEBYKEY will NOT automatically call DISPOSEEVENTSONALLPARENTS. These are two separate things. You may want to call them both back-to-back but this is NOT forced.          

            //Add support for SubscribeAnyEventByRow and ByColumn  TWO DIFFERENT THINGS

            //Remember to update REMOVE BY KEY if you have attached properties by x-y coordinates? or may not be necessary
            //anyway since this is a setting that you may want to keep if you may re-add removed item?

            //setattachedpropertyByKeyAtXY at x-y coordinates; perhaps, for this cases developers should just get the particular Border/Child and just update it individually at runtime?

            //WHAT ABOUT A PRE-SORT FOR ONE COLUMN?  TO SORT AS ITEMS ARE ADDED VIA A SEPARATE SORTED DICTIONARY?

            //1 Add methods for Accent and Cosmopolitan styles out-of-the-box - pre-built settings

            //2 Work on disabled color support for the entire listbox -  myListBox.IsEnabled = false;

            //3 ADDBUTTON ADDCHECKBOX ADDTEXTBOX control template assistance? Providing a simplified control template for AddButton 

            //4 Add more support for Images? What about adding images as byte arrays or from web server uri's?!?

            //5 Add support for adding FlowDocumentScrollViewer for wrapping Text around an image?! 
            //<FlowDocumentScrollViewer>
            //    <FlowDocument>                
            //        <Paragraph>
            //            <Floater Width="130" HorizontalAlignment="Left" Margin="0,0,5,5" Padding="3">
            //                <BlockUIContainer>
            //                    <Image Source="/FlowDocumentTest;component/dog.png" Width="100" /> 
            //                </BlockUIContainer>
            //            </Floater>
            //            Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
            //            Suspendisse et diam felis. Vestibulum ac nisl mi. 
            //            Etiam varius velit lobortis nibh vestibulum nec consequat velit pellentesque. 
            //            Cras commodo libero placerat nulla dapibus eget porttitor ligula tempor. 
            //            Donec nisl massa, congue et pretium sit amet, feugiat vel est. 
            //            Nulla dapibus metus in justo pulvinar sit amet viverra lorem rhoncus. 
            //            Integer placerat interdum massa et mattis.</Paragraph>
            //    </FlowDocument>
            //</FlowDocumentScrollViewer>
            #endregion
            
            base.EndInitializeComponent();

            mainGrid.Visibility = Visibility.Visible;

            TabControlService.SelectTab(tabCtl, 10);

            //);
            //this.SubscribeObservableOnParent<DataGrid, MouseButtonEventArgs>("masterDetail", "PreviewMouseDown", evPtrn => { System.Windows.MessageBox.Show("Fire away!"); });

           // this.SubscribeSingleClickOnParent<DataGrid>("foo", evPtrn => { System.Windows.MessageBox.Show("Fire away!"); });

            this.SubscribeObservableOnParent<DataGrid, MouseButtonEventArgs>("foo", "PreviewMouseDown", evPtrn => { System.Windows.MessageBox.Show("Fire away!"); }, (connectableObservable, actionDelegate) => { connectableObservable.Skip(2).Subscribe(actionDelegate); });
       
            //FasterWPF.Observables.ObservableHelper.FireObservableOnParent<MouseButtonEventArgs, DataGrid>(masterDetail, "PreviewMouseDown", new MouseButtonEventArgs(Mouse.PrimaryDevice, 100, MouseButton.Left));
  
 

            //DialogHelpers.ShowQuestionBoxDialog(            
        }
        
        //this is an OPTIONAL method for manually re-sizing controls upon Window Resize Event
        protected override void ResizeCorrectly()
        {
             //Sizing currently optimized for 1280 x 1024 (and/or other screen resolutions which maintain the same aspect ratio)

             Double windowHeight = base.WindowHeight; //Math.Abs((rect.Top - rect.Bottom));
             Double windowWidth = base.WindowWidth - 10;

             if (windowWidth > 0)
             {
                
                #region Resize Core Control, Menu Control, Tab Control

                    if (GlobalStoreService.ExistsInGlobalStore(GlobalStoreService.TabControlGuids.One, "CoreControlFull1"))
                    {
                        GlobalStoreService.GetFromGlobalStore<FrameworkElement>(GlobalStoreService.TabControlGuids.One, "CoreControlFull1").Height = windowHeight;
                        GlobalStoreService.GetFromGlobalStore<FrameworkElement>(GlobalStoreService.TabControlGuids.One, "CoreControlFull1").Width = windowWidth;
                    }
                    if (((FrameworkElement)Application.Current.Properties["CoreControlFull2"]) != null)
                    {
                        ((FrameworkElement)Application.Current.Properties["CoreControlFull2"]).Height = windowHeight;
                        ((FrameworkElement)Application.Current.Properties["CoreControlFull2"]).Width = windowWidth;
                    }
                    if (((FrameworkElement)Application.Current.Properties["MenuControl"]) != null)
                    {
                        ((FrameworkElement)Application.Current.Properties["MenuControl"]).Width = windowWidth;
                    }
                    if (((FrameworkElement)Application.Current.Properties["TabControl"]) != null)
                    {
                        ((FrameworkElement)Application.Current.Properties["TabControl"]).Width = windowWidth;
                    }

                    if (GlobalStoreService.ExistsInGlobalStore(GlobalStoreService.TabControlGuids.One, "MyListBox"))
                    {
                        GlobalStoreService.GetFromGlobalStore<FrameworkElement>(GlobalStoreService.TabControlGuids.One, "MyListBox").Height = windowHeight * .450;
                        GlobalStoreService.GetFromGlobalStore<FrameworkElement>(GlobalStoreService.TabControlGuids.One, "MyListBox").Width = windowWidth * .330;
                    }
                    if (GlobalStoreService.ExistsInGlobalStore(GlobalStoreService.TabControlGuids.One, "MyListView"))
                    {
                        if ((windowHeight * .450) > 21)
                        {
                            GlobalStoreService.GetFromGlobalStore<FrameworkElement>(GlobalStoreService.TabControlGuids.One, "MyListView").Height = (windowHeight * .450) - 21;
                        }
                        else
                        {
                            GlobalStoreService.GetFromGlobalStore<FrameworkElement>(GlobalStoreService.TabControlGuids.One, "MyListView").Height = (windowHeight * .450);
                        }

                        if ((windowWidth * .330) > 17)
                        {
                            GlobalStoreService.GetFromGlobalStore<FrameworkElement>(GlobalStoreService.TabControlGuids.One, "MyListView").Width = (windowWidth * .330) - 17;
                        }
                        else
                        {
                            GlobalStoreService.GetFromGlobalStore<FrameworkElement>(GlobalStoreService.TabControlGuids.One, "MyListView").Width = (windowWidth * .330);
                        }
                    }

                #endregion

                #region Re-size the Tab Item 1 User Control

                Border userControlChildComposite1 = null;

                if (this.TrySelectCompositeByKey(userCtlGuid1, out userControlChildComposite1))
                {
                    var handleToUserControl1 = userControlChildComposite1.GetParentFromComposite<UserControl>();
                    handleToUserControl1.Height = windowHeight * .892;
                    handleToUserControl1.Width = windowWidth * .990;

                    userControlChildComposite1.Visibility = Visibility.Visible;
                }

                #endregion

                #region Re-size the Tab Item 2 User Control

                Border userControlChildComposite2 = null;

                if (this.TrySelectCompositeByKey(userCtlGuid2, out userControlChildComposite2))
                {
                    var handleToUserControl2 = userControlChildComposite2.GetParentFromComposite<UserControl>();
                    handleToUserControl2.Height = windowHeight * .890;
                    handleToUserControl2.Width = windowWidth * .985;

                    //Re-size the content of the CustomTabItem which is the "real" TabItem
                    var TabItem2b = this.SelectFrameworkElementsByType<TabItem>().Where(tbItm =>
                    {
                        return tbItm.Cast<CustomTabItem>().Name == "CustomTabItem2";
                    }).First();

                    (TabItem2b.Content as FrameworkElement).Height = windowHeight * .890;
                    (TabItem2b.Content as FrameworkElement).Width = windowWidth * .985;
                }
                else
                {
                    //Re-size the content of the CustomTabItem which is the "real" TabItem
                    List<TabItem> ieTab2 = this.SelectFrameworkElementsByType<TabItem>().Where(tbItm =>
                    {
                        return tbItm.Cast<CustomTabItem>().Name == "CustomTabItem2";
                    }).ToList<TabItem>();

                    if (ieTab2 != null && ieTab2.Count > 0)
                    {
                        var TabItem2b = ieTab2.First();

                        (TabItem2b.Content as FrameworkElement).Height = windowHeight * .890;
                        (TabItem2b.Content as FrameworkElement).Width = windowWidth * .985;
                    }
                }

                #endregion

                #region Re-size the Tab Item 3 User Control

                Border userControlChildComposite3a = null;

                if (this.TrySelectCompositeByKey(userCtlGuid3, out userControlChildComposite3a))
                {
                    //Re-size User Control
                    var UserControl3a = userControlChildComposite3a.GetParentFromComposite<UserControl>();
                    UserControl3a.Height = windowHeight * .890;
                    UserControl3a.Width = windowWidth * .985;

                    //Re-size the content of the CustomTabItem which is the "real" TabItem
                    var TabItem3b = this.SelectFrameworkElementsByType<TabItem>().Where(tbItm =>
                    {
                        return tbItm.Cast<CustomTabItem>().Name == "CustomTabItem3";
                    }).First();
                    (TabItem3b.Content as FrameworkElement).Height = windowHeight * .890;
                    (TabItem3b.Content as FrameworkElement).Width = windowWidth * .985;
                }
                else
                {
                    //Re-size the content of the CustomTabItem which is the "real" TabItem                      
                    List<TabItem> ieTab3 = this.SelectFrameworkElementsByType<TabItem>().Where(tbItm =>
                    {
                        return tbItm.Cast<CustomTabItem>().Name == "CustomTabItem3";
                    }).ToList<TabItem>();

                    if (ieTab3 != null && ieTab3.Count > 0)
                    {
                        var TabItem3b = ieTab3.First();
                        (TabItem3b.Content as FrameworkElement).Height = windowHeight * .890;
                        (TabItem3b.Content as FrameworkElement).Width = windowWidth * .985;
                    }
                }

                #endregion

                #region Re-size the Tab Item 4 User Control

                Border userControlChildComposite4a = null;

                if (this.TrySelectCompositeByKey(userCtlGuid4, out userControlChildComposite4a))
                {
                    //Re-size User Control
                    var UserControl4a = userControlChildComposite4a.GetParentFromComposite<UserControl>();
                    UserControl4a.Height = windowHeight * .890;
                    UserControl4a.Width = windowWidth * .985;

                    //Re-size the content of the CustomTabItem which is the "real" TabItem
                    var TabItem4b = this.SelectFrameworkElementsByType<TabItem>().Where(tbItm =>
                    {
                        return tbItm.Cast<CustomTabItem>().Name == "CustomTabItem4";
                    }).First();
                    (TabItem4b.Content as FrameworkElement).Height = windowHeight * .890;
                    (TabItem4b.Content as FrameworkElement).Width = windowWidth * .985;
                }
                else
                {
                    //Re-size the content of the CustomTabItem which is the "real" TabItem                      
                    List<TabItem> ieTab4 = this.SelectFrameworkElementsByType<TabItem>().Where(tbItm =>
                    {
                        return tbItm.Cast<CustomTabItem>().Name == "CustomTabItem4";
                    }).ToList<TabItem>();

                    if (ieTab4 != null && ieTab4.Count > 0)
                    {
                        var TabItem4b = ieTab4.First();
                        (TabItem4b.Content as FrameworkElement).Height = windowHeight * .890;
                        (TabItem4b.Content as FrameworkElement).Width = windowWidth * .985;
                    }
                }

                #endregion

                #region Re-size the Tab Item 6 User Control

                Border userControlChildComposite6 = null;

                if (this.TrySelectCompositeByKey(userCtlGuid6, out userControlChildComposite6))
                {
                    var handleToUserControl6 = userControlChildComposite6.GetParentFromComposite<UserControl>();
                    handleToUserControl6.Height = windowHeight * .890;
                    handleToUserControl6.Width = windowWidth * .985;
                }

                #endregion

                #region Re-size the Tab Item 9 User Control

                Border userControlChildComposite9a = null;

                if (this.TrySelectCompositeByKey(userCtlGuid9, out userControlChildComposite9a))
                {
                    //Re-size User Control
                    var UserControl9a = userControlChildComposite9a.GetParentFromComposite<UserControl>();
                    UserControl9a.Height = windowHeight * .890;
                    UserControl9a.Width = windowWidth * .985;

                    //Re-size the content of the CustomTabItem which is the "real" TabItem
                    var TabItem9b = this.SelectFrameworkElementsByType<TabItem>().Where(tbItm =>
                    {
                        return tbItm.Cast<CustomTabItem>().Name == "CustomTabItem9";
                    }).First();
                    (TabItem9b.Content as FrameworkElement).Height = windowHeight * .890;
                    (TabItem9b.Content as FrameworkElement).Width = windowWidth * .985;
                }
                else
                {
                    //Re-size the content of the CustomTabItem which is the "real" TabItem                      
                    List<TabItem> ieTab9 = this.SelectFrameworkElementsByType<TabItem>().Where(tbItm =>
                    {
                        return tbItm.Cast<CustomTabItem>().Name == "CustomTabItem9";
                    }).ToList<TabItem>();

                    if (ieTab9 != null && ieTab9.Count > 0)
                    {
                        var TabItem9b = ieTab9.First();
                        (TabItem9b.Content as FrameworkElement).Height = windowHeight * .890;
                        (TabItem9b.Content as FrameworkElement).Width = windowWidth * .985;
                    }
                }

                #endregion

                #region Re-size the Tab Item 10 User Control

                Border userControlChildComposite10a = null;

                if (this.TrySelectCompositeByKey(userCtlGuid10, out userControlChildComposite10a))
                {
                    //Re-size User Control
                    var UserControl10a = userControlChildComposite10a.GetParentFromComposite<UserControl>();
                    UserControl10a.Height = windowHeight * .890;
                    UserControl10a.Width = windowWidth * .985;

                    //Re-size the content of the CustomTabItem which is the "real" TabItem
                    var TabItem10b = this.SelectFrameworkElementsByType<TabItem>().Where(tbItm =>
                    {
                        return tbItm.Cast<CustomTabItem>().Name == "CustomTabItem10";
                    }).First();
                    (TabItem10b.Content as FrameworkElement).Height = windowHeight * .890;
                    (TabItem10b.Content as FrameworkElement).Width = windowWidth * .985;
                }
                else
                {
                    //Re-size the content of the CustomTabItem which is the "real" TabItem                      
                    List<TabItem> ieTab10 = this.SelectFrameworkElementsByType<TabItem>().Where(tbItm =>
                    {
                        return tbItm.Cast<CustomTabItem>().Name == "CustomTabItem10";
                    }).ToList<TabItem>();

                    if (ieTab10 != null && ieTab10.Count > 0)
                    {
                        var TabItem10b = ieTab10.First();
                        (TabItem10b.Content as FrameworkElement).Height = windowHeight * .890;
                        (TabItem10b.Content as FrameworkElement).Width = windowWidth * .985;
                    }
                }

                #endregion
                
            }
        }

    }//end of class    
}//end of namespace